package com.qiandw.myblog.service.impl;

import com.qiandw.myblog.entity.Post;
import com.qiandw.myblog.mapper.PostMapper;
import com.qiandw.myblog.service.PostService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * 帖子服务实现类
 *
 * @author KG
 */
@Service
public class PostServiceImpl extends BaseServiceImpl<PostMapper, Post> implements PostService {

    @Override
    public void join(Map<String, Object> map, String field) {
        Map<String, Object> joinColumns = new HashMap<>();
        if (map == null || map.get(field) == null) {
            return;
        }
        //字段的值
        String linkfieldValue = map.get(field).toString();
        Post post = this.getById(linkfieldValue);
        if (post == null) {
            return;
        }

        joinColumns.put("id", post.getId());
        joinColumns.put("title", post.getTitle());
        //TODO 使用hutool工具类
//        joinColumns.put("created", DateUtil.formatDate(post.getCreated()));
        map.put("post", joinColumns);
    }
}
